<script>
/**
 * @desc 首页滑块展示组件
 */

import { navTo } from '@/utils'
export default {
  name: 'home-slide',
  props: {
    list: Array
  },
  methods: {
    handleClick(id) {
      navTo({ name: 'travel-detail', query: { id } })
    }
  }
}
</script>

<template>
  <div class="scroll-container">
    <scroll-view scroll-x class="home-slide">
      <div
        v-for="v in list"
        :key="v.id"
        class="slide-item"
        @click="handleClick(v.id)"
      >
        <img :src="v.url" class="preview-img" mode="aspectFill">
        <p class="title">{{v.title}}</p>
        <p class="price">￥{{v.price}}</p>
      </div>
    </scroll-view>
  </div>
</template>

<style lang="scss" scoped>
.scroll-container {
  margin: 10px;
}
.home-slide {
  white-space: nowrap;
  font-size: 16px;

  .slide-item {
    display: inline-block;
    width: 80%;
    height: 300rpx;
    padding: 10px;
    &:not(:last-child) {
      margin-right: 10px;
    }

    .preview-img {
      display: block;
      width: 100%;
      height: 100%;
      margin-bottom: 10px;
      border-radius: 5px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
      background-color: $main-background-color;
    }

    .title {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: center;
    }

    .price {
      color: $main-color;
      text-align: center;
      font-weight: bold;
    }
  }
}
</style>
